Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./year2.RDS")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2021-06-30"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2021-06-30"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 358)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 11.50306 11.54518 11.58680 11.62793 11.66857 11.70874 11.74846 11.78773
## [9] 11.82656 11.86498 11.90298 11.94059 11.97781 12.01465 12.05113 12.08729
## [17] 12.12314 12.15863 12.19374 12.22843 12.26267 12.29642 12.32966 12.36234
## [25] 12.39443 12.42590 12.45671 12.48737 12.51824 12.54912 12.57977 12.60998
## [33] 12.63953 12.66821 12.69580 12.72207 12.74824 12.77540 12.80319 12.83125
## [41] 12.85921 12.88669 12.91334 12.93878 12.96265 12.98459 13.00422 13.02118
## [49] 13.03766 13.05556 13.07407 13.09240 13.10974 13.12530 13.13826 13.14783
## [57] 13.15321 13.15507 13.15472 13.15229 13.14790 13.14169 13.13379 13.12431
## [65] 13.11340 13.10118 13.08778 13.07332 13.05795 13.04177 13.02059 12.99165
## [73] 12.95726 12.91975 12.88143 12.84463 12.81165 12.78482 12.75949 12.73004
## [81] 12.69733 12.66222 12.62558 12.58826 12.55112 12.51503 12.48086 12.44945
## [89] 12.42168 12.39841 12.37757 12.35670 12.33600 12.31570 12.29602 12.27718
## [97] 12.25941 12.24291 12.22792 12.21457 12.20276 12.19236 12.18323 12.17524
## [105] 12.16826 12.16215 12.15676 12.15198 12.14766 12.14368 12.13988 12.13732
## [113] 12.13685 12.13805 12.14052 12.14384 12.14760 12.15140 12.15482 12.15745
## [121] 12.16049 12.16523 12.17135 12.17854 12.18650 12.19492 12.20349 12.21191
## [129] 12.21986 12.22704 12.23314 12.23786 12.24185 12.24595 12.25008 12.25419
## [137] 12.25821 12.26208 12.26573 12.26910 12.27213 12.27368 12.27299 12.27052
## [145] 12.26676 12.26217 12.25723 12.25241 12.24818 12.24503 12.24342 12.24383
## [153] 12.24673 12.25259 12.26190 12.27352 12.28599 12.29925 12.31325 12.32793
## [161] 12.34325 12.35913 12.37554 12.39242 12.40971 12.42737 12.44532 12.46722
## [169] 12.49595 12.53033 12.56919 12.61136 12.65567 12.70094 12.74599 12.78966
## [177] 12.83077 12.86815 12.90063 12.92702 12.94616 12.96250 12.98089 13.00082
## [185] 13.02172 13.04308 13.06435 13.08498 13.10445 13.12222 13.13774 13.15048
## [193] 13.15989 13.16545 13.16661 13.16283 13.15358 13.13684 13.11181 13.07976
## [201] 13.04198 12.99973 12.95431 12.90699 12.85905 12.81175 12.76639 12.72425
## [209] 12.68659 12.64810 12.60367 12.55491 12.50339 12.45071 12.39847 12.34826
## [217] 12.30166 12.26027 12.22083 12.17935 12.13636 12.09237 12.04792 12.00352
## [225] 11.95971 11.91699 11.87590 11.83695 11.80068 11.76760 11.73568 11.70289
## [233] 11.66982 11.63704 11.60513 11.57467 11.54623 11.52039 11.49772 11.47666
## [241] 11.45548 11.43451 11.41409 11.39454 11.37621 11.35943 11.34452 11.33183
## [249] 11.32169 11.31444 11.31040 11.30951 11.31127 11.31539 11.32156 11.32950
## [257] 11.33890 11.34946 11.36089 11.37289 11.38889 11.41170 11.44008 11.47282
## [265] 11.50866 11.54639 11.58477 11.62258 11.65856 11.69151 11.72018 11.74334
## [273] 11.76600 11.79306 11.82316 11.85490 11.88693 11.91786 11.94631 11.97092
## [281] 11.99030 12.00507 12.01708 12.02682 12.03479 12.04150 12.04743 12.05309
## [289] 12.05897 12.06557 12.07338 12.08291 12.09465 12.10528 12.11190 12.11563
## [297] 12.11759 12.11890 12.12069 12.12406 12.13015 12.14007 12.15269 12.16606
## [305] 12.18010 12.19472 12.20982 12.22532 12.24113 12.25716 12.27332 12.28953
## [313] 12.30569 12.32172 12.33752 12.35302 12.36924 12.38704 12.40605 12.42589
## [321] 12.44620 12.46660 12.48672 12.50619 12.52465 12.54171 12.55701 12.57017
## [329] 12.58242 12.59507 12.60788 12.62063 12.63310 12.64505 12.65626 12.66649
## [337] 12.67553 12.68375 12.69166 12.69923 12.70641 12.71319 12.71952 12.72536
## [345] 12.73069 12.73547 12.73967 12.74325 12.74617 12.74839 12.74989 12.75071
## [353] 12.75090 12.75051 12.74957 12.74812 12.74622 12.74390
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./site_objects/wrf_a_year2.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 358)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 10.73722 10.82693 10.91488 11.00106 11.08547 11.16808 11.24890 11.32789
## [9] 11.40507 11.48040 11.55389 11.62552 11.69527 11.76314 11.82912 11.89316
## [17] 11.95526 12.01545 12.07378 12.13027 12.18495 12.23787 12.28905 12.33853
## [25] 12.38635 12.43253 12.47712 12.51975 12.56016 12.59849 12.63488 12.66949
## [33] 12.70246 12.73395 12.76409 12.79305 12.81997 12.84406 12.86559 12.88482
## [41] 12.90201 12.91740 12.93126 12.94385 12.95543 12.96625 12.97658 12.98666
## [49] 12.99385 12.99610 12.99456 12.99036 12.98466 12.97860 12.97334 12.97001
## [57] 12.96976 12.97125 12.97233 12.97299 12.97320 12.97292 12.97213 12.97081
## [65] 12.96893 12.96646 12.96338 12.95966 12.95527 12.95018 12.94464 12.93879
## [73] 12.93249 12.92561 12.91799 12.90949 12.89998 12.88931 12.87744 12.86451
## [81] 12.85064 12.83595 12.82057 12.80460 12.78817 12.77141 12.75441 12.73732
## [89] 12.72024 12.70330 12.68710 12.67184 12.65705 12.64226 12.62697 12.61073
## [97] 12.59305 12.57347 12.55149 12.52507 12.49317 12.45689 12.41729 12.37546
## [105] 12.33248 12.28942 12.24737 12.20740 12.17059 12.13803 12.11079 12.08262
## [113] 12.04806 12.00940 11.96893 11.92894 11.89170 11.85951 11.83465 11.81940
## [121] 11.81130 11.80615 11.80365 11.80354 11.80552 11.80931 11.81463 11.82120
## [129] 11.82872 11.83692 11.84552 11.85423 11.86581 11.88245 11.90294 11.92609
## [137] 11.95073 11.97565 11.99967 12.02160 12.04025 12.05936 12.08303 12.11060
## [145] 12.14144 12.17487 12.21025 12.24691 12.28422 12.32151 12.35813 12.39343
## [153] 12.42675 12.45744 12.48484 12.51070 12.53707 12.56378 12.59064 12.61748
## [161] 12.64411 12.67036 12.69605 12.72100 12.74503 12.76797 12.78963 12.81124
## [169] 12.83397 12.85755 12.88172 12.90619 12.93071 12.95500 12.97879 13.00181
## [177] 13.02379 13.04447 13.06356 13.08081 13.09594 13.11103 13.12803 13.14648
## [185] 13.16592 13.18590 13.20596 13.22564 13.24449 13.26205 13.27785 13.29145
## [193] 13.30238 13.31019 13.31442 13.31462 13.31032 13.30214 13.29115 13.27757
## [201] 13.26160 13.24346 13.22337 13.20153 13.17817 13.15350 13.12772 13.10107
## [209] 13.07374 13.04247 13.00486 12.96242 12.91669 12.86919 12.82144 12.77497
## [217] 12.73130 12.69195 12.65271 12.60895 12.56155 12.51139 12.45937 12.40636
## [225] 12.35326 12.30094 12.25029 12.20219 12.15754 12.11721 12.07759 12.03514
## [233] 11.99086 11.94573 11.90076 11.85693 11.81525 11.77671 11.74231 11.71020
## [241] 11.67806 11.64619 11.61486 11.58436 11.55498 11.52700 11.50071 11.47639
## [249] 11.45432 11.43480 11.41809 11.40358 11.39049 11.37890 11.36889 11.36054
## [257] 11.35394 11.34917 11.34632 11.34545 11.34741 11.35268 11.36085 11.37148
## [265] 11.38414 11.39842 11.41388 11.43009 11.44663 11.46307 11.47899 11.49395
## [273] 11.51061 11.53125 11.55494 11.58069 11.60757 11.63462 11.66087 11.68536
## [281] 11.70716 11.72878 11.75311 11.77966 11.80795 11.83750 11.86783 11.89847
## [289] 11.92893 11.95875 11.98742 12.01449 12.03947 12.06289 12.08569 12.10795
## [297] 12.12978 12.15128 12.17255 12.19369 12.21480 12.23597 12.25721 12.27840
## [305] 12.29950 12.32047 12.34125 12.36180 12.38207 12.40201 12.42159 12.44074
## [313] 12.45942 12.47759 12.49520 12.51220 12.52890 12.54559 12.56221 12.57869
## [321] 12.59497 12.61097 12.62664 12.64191 12.65670 12.67096 12.68462 12.69761
## [329] 12.71020 12.72268 12.73497 12.74699 12.75868 12.76996 12.78076 12.79101
## [337] 12.80065 12.80977 12.81854 12.82695 12.83499 12.84265 12.84993 12.85681
## [345] 12.86329 12.86936 12.87501 12.88023 12.88502 12.88937 12.89329 12.89679
## [353] 12.89987 12.90256 12.90485 12.90675 12.90827 12.90942
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./site_objects/wrf_b_year2.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 358)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 10.84878 10.91019 10.97054 11.02980 11.08797 11.14503 11.20096 11.25575
## [9] 11.30939 11.36186 11.41313 11.46321 11.51207 11.55970 11.60607 11.65122
## [17] 11.69515 11.73791 11.77950 11.81996 11.85931 11.89758 11.93477 11.97093
## [25] 12.00606 12.04020 12.07337 12.10489 12.13429 12.16188 12.18796 12.21287
## [33] 12.23691 12.26040 12.28365 12.30697 12.33015 12.35273 12.37468 12.39596
## [41] 12.41653 12.43636 12.45541 12.47365 12.49104 12.50754 12.52312 12.53775
## [49] 12.55253 12.56824 12.58435 12.60030 12.61555 12.62956 12.64178 12.65168
## [57] 12.65870 12.66308 12.66555 12.66628 12.66543 12.66317 12.65968 12.65512
## [65] 12.64967 12.64348 12.63674 12.62962 12.62227 12.61488 12.60668 12.59695
## [73] 12.58593 12.57384 12.56093 12.54743 12.53356 12.51956 12.50310 12.48225
## [81] 12.45785 12.43073 12.40175 12.37172 12.34151 12.31194 12.28385 12.25808
## [89] 12.23547 12.21686 12.19969 12.18122 12.16194 12.14239 12.12309 12.10455
## [97] 12.08729 12.07184 12.05871 12.04794 12.03902 12.03165 12.02553 12.02038
## [105] 12.01590 12.01179 12.00776 12.00350 11.99874 11.99317 11.98649 11.97926
## [113] 11.97226 11.96551 11.95904 11.95288 11.94706 11.94161 11.93656 11.93194
## [121] 11.92877 11.92777 11.92852 11.93062 11.93365 11.93721 11.94087 11.94424
## [129] 11.94688 11.94841 11.94839 11.94643 11.94150 11.93350 11.92332 11.91185
## [137] 11.90002 11.88871 11.87885 11.87131 11.86702 11.86294 11.85585 11.84642
## [145] 11.83531 11.82316 11.81065 11.79841 11.78712 11.77743 11.76999 11.76547
## [153] 11.76451 11.76777 11.77592 11.78833 11.80369 11.82158 11.84161 11.86336
## [161] 11.88645 11.91047 11.93501 11.95967 11.98405 12.00774 12.03035 12.05549
## [169] 12.08643 12.12224 12.16197 12.20469 12.24947 12.29536 12.34143 12.38674
## [177] 12.43036 12.47134 12.50876 12.54167 12.56914 12.59560 12.62562 12.65847
## [185] 12.69345 12.72983 12.76688 12.80388 12.84013 12.87488 12.90743 12.93704
## [193] 12.96301 12.98460 13.00110 13.01179 13.01594 13.01385 13.00669 12.99507
## [201] 12.97959 12.96088 12.93953 12.91614 12.89134 12.86573 12.83991 12.81449
## [209] 12.79008 12.76160 12.72497 12.68224 12.63550 12.58680 12.53821 12.49182
## [217] 12.44967 12.41386 12.37869 12.33790 12.29268 12.24420 12.19365 12.14221
## [225] 12.09106 12.04138 11.99434 11.95114 11.91296 11.88097 11.85096 11.81867
## [233] 11.78515 11.75148 11.71872 11.68794 11.66022 11.63661 11.61820 11.60609
## [241] 11.60002 11.59899 11.60200 11.60803 11.61610 11.62520 11.63433 11.64248
## [249] 11.64866 11.65185 11.65106 11.64996 11.65229 11.65720 11.66383 11.67131
## [257] 11.67880 11.68543 11.69034 11.69267 11.69251 11.69078 11.68788 11.68421
## [265] 11.68018 11.67617 11.67260 11.66985 11.66835 11.66847 11.67063 11.67522
## [273] 11.67996 11.68277 11.68436 11.68546 11.68680 11.68908 11.69304 11.69939
## [281] 11.70885 11.72183 11.73787 11.75641 11.77688 11.79872 11.82137 11.84426
## [289] 11.86682 11.88851 11.90874 11.92696 11.94260 11.95981 11.98214 12.00818
## [297] 12.03651 12.06570 12.09433 12.12098 12.14423 12.16266 12.17725 12.19008
## [305] 12.20136 12.21133 12.22019 12.22819 12.23552 12.24243 12.24913 12.25584
## [313] 12.26278 12.27018 12.27825 12.28723 12.29701 12.30726 12.31779 12.32845
## [321] 12.33906 12.34944 12.35945 12.36889 12.37761 12.38544 12.39220 12.39772
## [329] 12.40237 12.40661 12.41047 12.41396 12.41709 12.41987 12.42232 12.42446
## [337] 12.42629 12.42783 12.42909 12.43004 12.43067 12.43096 12.43090 12.43048
## [345] 12.42967 12.42847 12.42685 12.42481 12.42232 12.41935 12.41586 12.41188
## [353] 12.40742 12.40252 12.39718 12.39144 12.38532 12.37882
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./site_objects/wrf_c_year2.rda")
keeping in case
#save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
#save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
#save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
#save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
#save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
#save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
#save(both_ymina, file = "./plotly_objs/both_ymina.rda")
#save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
#save(both_yminb, file = "./plotly_objs/both_yminb.rda")
#save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
#save(both_yminc, file = "./plotly_objs/both_yminc.rda")
#save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")